package sets.collection;

import sets.collection.domain.Student;

import java.util.ArrayList;
import java.util.Collection;
/*
Collection的常用方法：
    add：添加
    clear：清空所有
    isEmpty：判断集合是否为空
    remove：根据元素做删除,bool类型返回值
    contains:判断集合是否包含给定的元素
    size:返回元素个数
 */
public class CollectionDemo01 {
    public static void main(String[] args) {
        Collection<Student> c = new ArrayList<>();
        c.add(new Student("张三",21));
        c.add(new Student("lisa",20));
        c.add(new Student("JACK",25));
        System.out.println(c);

        //remove和contains方法  底层依赖于对象的equals方法，需要重写
        c.remove(new Student("lisa",20));
        System.out.println(c);
        System.out.println(c.contains(new Student("张三", 21)));

    }

    private static void baseMethod() {
        //以多态的形式创建集合对象，调用集合中的公有方法
        Collection<String> c = new ArrayList<>();
        //bool类型返回值
        c.add("张三");
        c.add("李四");
        c.add("王五");
        System.out.println(c);

        c.remove("李四");
        System.out.println(c);

        boolean b = c.contains("张三");
        System.out.println(b);

        System.out.println(c.size());
    }
}
